package com.example.bughuangkai.service.impl;

import com.example.bughuangkai.entity.Bug;
import com.example.bughuangkai.mapper.BugMapper;
import com.example.bughuangkai.service.BugService;
import com.example.bughuangkai.vo.ReturnT;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description bug
 * @author 黄凯
 * @date 2022-02-12
 */
@Service
public class BugServiceImpl implements BugService {

	@Resource
	private BugMapper bugMapper;


	@Override
	public Object insert(Bug bug) {

		// valid
		if (bug == null) {
			return ReturnT.error("必要参数缺失");
        }

		bugMapper.insert(bug);
        return ReturnT.success();
	}


	@Override
	public ReturnT delete(int id) {
		int ret = bugMapper.delete(id);
		return ret>0?ReturnT.success():ReturnT.error();
	}


	@Override
	public ReturnT update(Bug bug) {
		int ret = bugMapper.update(bug);
		return ret>0?ReturnT.success():ReturnT.error();
	}


	@Override
	public Bug load(int id) {
		return bugMapper.load(id);
	}


	@Override
	public PageInfo<Bug> pageList(Page page) {
		PageHelper.startPage(page.getPageNum(),page.getPageSize());
		List<Bug> list = bugMapper.pageList();
		PageInfo<Bug> pageInfo = new PageInfo<Bug>(list);
		return pageInfo;
	}

}